<template>
<div class="flex_center_between logout_wrap" v-if="!isApp && userInfo.isLogin">
    <div class="logout" @click="logout">
      <p>退出登录</p>
    </div>
</div>
</template>

<script>
import { mapState, mapActions } from 'vuex';
import { logout } from '@/api';
import DZUtils from '@/utils/DZUtils';
import AppUtils from '@/utils/appUtils';

export default {
  data() {
    return {
      publicPath: this.global.publicPath,
      isApp: true,
    };
  },
  computed: mapState(['userInfo']),
  mounted() {
    this.isApp = AppUtils.browser.isApp;
  },
  methods: {
    async logout() {
      try {
        const { returnCode, returnInfo } = await logout(this.userInfo.fundAccount);
        if (returnCode === '0') {
          window.location.href = `${this.publicPath}/index`;
        } else {
          DZUtils.iDialog(returnInfo);
        }
      } catch (ex) {
        console.log('logout ex', ex);
        // DZUtils.iDialog(ex.message);
      }
    }
  }
};
</script>

<style lang="less" scoped>
.logout_wrap{
  .logout{
    margin: 0 auto 15px;
    padding: 8px 50px;
    background: #fff;
    border-radius: 18px;
    border: 1px solid #8fb4ff;
    color: @-color-primary;
    font-size: 15px;
  }
}
</style>